﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace MoeRabbit
{
    class Webclient_cat
    {
        /// <summary>
        /// 获取html源码的通用类
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string GetWebClient(string url)
        {

            System.Net.ServicePointManager.ServerCertificateValidationCallback += (send, certificate, chain, sslPolicyErrors) => { return true; };//这一句是强制忽略证书错误
            string strHTML = "";
            try
            {
                WebClient myWebClient = new WebClient();
                myWebClient.Headers.Add("User-Agent", " Mozilla/5.0 (Linux; U; Android 6.0.4; Nexus 5 Build/KTU84P) AppleWebkit/564.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
                myWebClient.Headers.Add("Accept-Language", "zh-cn");
                Stream myStream = myWebClient.OpenRead(url);
                StreamReader sr = new StreamReader(myStream, System.Text.Encoding.GetEncoding("utf-8"));
                strHTML = sr.ReadToEnd();
                myStream.Close();
                sr.Close();
                myWebClient.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return strHTML;
        }


    }
}
